package com.wx.spring.ioc.parsing;

import com.wx.spring.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

/**
 * @author wx
 * @Description: 解析资源接口
 * @date 2019/1/11 001111:20
 */
public interface ParsingResources {
    /**
     * @param contextConfigLocation 资源路径
     * @description: 解析资源内容到容器中
     * @author: wx
     * @date: 2019/1/11 0011
     * @return: void
     */
    void parsingContent(String contextConfigLocation) throws DocumentException;


    /**
     * @description: 获取xml Elements对象
     * @author: wx
     * @date: 2019/1/11 0011
     * @param contextConfigLocation
     * @return: java.util.List<org.dom4j.Element>
     */
    default List<Element> getXmlElements(String contextConfigLocation) throws DocumentException {
        // 创建saxReader对象
        SAXReader reader = new SAXReader();
        String pathName = Constants.PATH + contextConfigLocation;
        // 通过read方法读取一个文件 转换成Document对象
        Document document = reader.read(new File(pathName));
        //获取根节点元素
        Element node = document.getRootElement();
        if (node == null) {
            return null;
        }
        //获取所有的bean
        List<Element> elementsList = node.elements();
        return elementsList;

    }


}
